<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="com.dwusoft.cache.util.Validator"%>
<%@ include file="/common/import.jsp"%>
<!DOCTYPE html>
<%
String userEname = (String)session.getAttribute("userEname");
String userEmail = (String)session.getAttribute("userEmail");
String uEmail = (String)session.getAttribute("uEmail");

String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

//如果为空,则直接跳转到passport/reg/passport-mn.action
if(Validator.isNull(userEname) ||Validator.isNull(userEmail)||Validator.isNull(uEmail) ){
	response.sendRedirect(basePath+"/passport/reg/passport-mn.action");
}
 %>
 

<html>
	<head>
		<title>安全 验证</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
		
		<link rel="stylesheet" href="${ctx}/css/reg/demo.css">
		<link rel="stylesheet" href="${ctx}/css/reg/sky-forms.css">

		<script src="${ctx}/js/md5.js"></script>
		<script src="${ctx}/js/reg/jquery.validate.min.js"></script>
		<!--[if lt IE 10]>
			<script src="${ctx}/js/reg/jquery.placeholder.min.js"></script>
		<![endif]-->	
		
		
		<script type="text/javascript">

		document.onkeydown = function (e) {
			var ev = window.event || e;
			var code = ev.keyCode || ev.which;
			if (code == 116) {
				if(ev.preventDefault) {
					ev.preventDefault();
				} else {
					ev.keyCode = 0;
					ev.returnValue = false;
				}
			}
		}

		$(function() {
			//注册表单提交
			var regForm = '#sky-form';
			$(regForm).form({
				onSubmit : function() {
					//多层校验
					var checkNum = $("#checkNum").val();
					if(checkNum == null || checkNum.trim() == ""){
						$.messager.alert('提交结果', '验证码不能为空', 'warning');
						return false;
					}
					return true;
				},
				success : function(data) {
					var result = jQuery.parseJSON(data);
					if (result.flag == 'T') {
						window.location.href='${ctx}/passport/reg/update-pwd-page.action';
					} else {
						$.messager.alert('提交结果', '验证码不正确', 'error',function(){
							clearForm();
						});
					}
				},
				error:function(data){
					$.messager.alert('提交结果', '与服务器连接失败', 'error',function(){
						clearForm();
					});
				}
			});
		});
		
		//清空部分表单
		function clearForm(){
			$("#checkNum").val("");
		}
		
		//发送邮件
		function sndEmail(){
			var email = $("#uel").val();
			if(email == null || email.trim() == ""){
				$.messager.alert('提交结果', '邮箱地址不能为空', 'error');
				return false;
			}
			//正则二次判断邮箱格式
	/*		var reg =/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;    
	        if(!reg.test(email)){    
	            $.messager.alert('提交结果', '邮箱格式不正确', 'error');
	            return false;
	        }
	  */      
	        //发送邮箱
	       $.ajax({
	       		url:'${ctx}/passport/reg/snd-email.action',
	       		type:'post',
	       		data:'userEmail='+email,
	       		success:function(data){
	       			var result = jQuery.parseJSON(data);
					if (result.flag == 'T') {
						$.messager.alert('提交结果', '邮件发送成功', 'info');
					} else {
						$.messager.alert('提交结果', result.msg, 'error');
					}
	       		},
	       		error:function(data){
	       			$.messager.alert('提交结果', '与服务器连接失败', 'error');
	       		}
	       });
		}
		
		</script>	
	</head>
	<body class="bg-cyan">
		<div class="body body-s">		
			<form action="${ctx}/passport/reg/checkRandNum.action" id="sky-form" class="sky-form" method="post" >
				<input type="hidden" name="_uel" id="uel" value="<%=URLEncoder.encode(userEmail)%>">
				<header>仅限测试展示,挖的微软的界面<a href="${ctx}">登录</a></header>
				<fieldset>					
					<section>
						<label class="input">
							<i class="icon-append icon-user"></i>
							<input type="text" name="email" placeholder="邮箱地址" value="<%=uEmail%>" disabled="disabled">
							<b class="tooltip tooltip-bottom-right">请输入用户名</b>
						</label>
						<input type="button" id="btn" onclick="sndEmail();" value="免费获取验证码" />
						<script type="text/javascript">
						var wait=60;
						function time(o) {
								if (wait == 0) {
									o.removeAttribute("disabled");			
									o.value="免费获取验证码";
									wait = 60;
								} else {
									o.setAttribute("disabled", true);
									o.value="重新发送(" + wait + ")";
									wait--;
									setTimeout(function() {
										time(o);
									},
									1000);
								}
							}
						document.getElementById("btn").onclick=function(){
							time(this);
							sndEmail();
						};
						</script>
						
						
						
					</section>
				</fieldset>
				<fieldset>
					<section>
						<label class="input">
							<i class="icon-append icon-user"></i>
							<input type="text" name="checkNum" id="checkNum" placeholder="验证码" >
							<b class="tooltip tooltip-bottom-right">请输入验证码</b>
						</label>
					</section>
				<footer>
					<button type="submit" class="button" >下一步</button>
				</footer>
			</form>			
		</div>
	</body>
</html>